<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData"></Table>
        </Row>
        <div style="margin: 10px;overflow: hidden;height: 36px;">
          <div style="float: right;">
            <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
          </div>
        </div>
      </Card>
      <Modal :width="600" title="详情"
             v-model="showCurrentTableData"
             ok-text="确定"
             cancel-text="取消"
             @on-ok=""
             @on-cancel=""
             class-name="vertical-center-modal"
             class="Modal-Detail-div">
        <Form label-position="top">
          <FormItem label="姓名">
            <div class="dataDetail-div" v-text="dataDetail.name"></div>
          </FormItem>
          <FormItem label="性别" v-if="dataDetail.sex">
            <div class="dataDetail-div" v-text="dataDetail.sex"></div>
          </FormItem>
          <FormItem label="年龄" v-if="dataDetail.age">
            <div class="dataDetail-div" v-text="dataDetail.age"></div>
          </FormItem>
          <FormItem label="出生日期" v-if="dataDetail.birthday">
            <div class="dataDetail-div" v-text="dataDetail.birthday"></div>
          </FormItem>
          <FormItem label="身份证号" v-if="dataDetail.idcard">
            <div class="dataDetail-div" v-text="dataDetail.idcard"></div>
          </FormItem>
          <FormItem label="手机号" v-if="dataDetail.mobile">
            <div class="dataDetail-div" v-text="dataDetail.mobile"></div>
          </FormItem>
          <FormItem label="部门" v-if="dataDetail.deps">
            <div class="dataDetail-div" v-text="dataDetail.deps"></div>
          </FormItem>
          <FormItem label="身份" v-if="dataDetail.station">
            <div class="dataDetail-div" v-text="dataDetail.station.title"></div>
          </FormItem>
          <FormItem label="在职状态" v-if="dataDetail.status">
            <div class="dataDetail-div" v-text="dataDetail.status.title"></div>
          </FormItem>
          <FormItem label="离退休时间" v-if="dataDetail.expect_retired_date">
            <div class="dataDetail-div" v-text="dataDetail.expect_retired_date"></div>
          </FormItem>
        </Form>
      </Modal>
    </Row>
  </div>
</template>

<script>
  import Util from '../../libs/util';
  export default {
    components: {},
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        id: '',
        searchConName: '',
        searchConTel: '',
        showCurrentTableData: false,
        loading: true,
        showCurrentColumns: [],
        editInlineAndCellData: [],
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'name',
            title: '姓名',
          },
          {
            key: 'department_name',
            title: '部门',
          },
          {
            key: 'time',
            title: '离退休日期',
          },
          /*{
            title: 'Action',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      var data = params.row;
                      this.show(params.index, data);
                    }
                  }
                }, '详情'),
                /!*h('Button', {
                 props: {
                 type: 'error',
                 size: 'small'
                 },
                 on: {
                 click: () => {
                 //this.remove(params.index)
                 }
                 }
                 }, '删除')*!/
              ]);
            }
          }*/
        ],
        data: [],
        dataDetail: {},
        initTable: [],
      };
    },
    mounted () {
      this.getData();
    },
    methods: {
      getData () {
        var _this = this;
        var data = {
          type: 'retired',
          //state: '2',
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          page: _this.page,
          size: _this.size,
        };
        var params = {
          url: '/user/retired/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.total = res.rows;
            _this.data = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      handleSearch () {
        var _this = this;
        _this.page = 1;
        var searchConName = _this.searchConName;
      },
      changePage (page) {
        var _this = this;
        console.log('page', page);
        _this.page = page;
        _this.getData();
      },
      onRowData: function (data, index) {
        var _this = this;
        _this.show(index, data);
      },
      show: function (index, data) {
        var _this = this;
        var id = data.id;
        _this.id = id;

        var data = {
          id: _this.id,
        };
        var params = {
          url: '/user/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var sex = _data.sex;
            if (sex == 'male') {
              _data.sex = '男';
            } else if (sex == 'female') {
              _data.sex = '女';
            }
            var departments = _data.departments;
            var dep_arr = [];
            for (var k in departments) {
              if (!departments[k]) {
                continue;
              }
              var name = departments[k].name;
              dep_arr.push(name);
            }
            _data.deps = dep_arr.join(' ， ');
            _this.dataDetail = _data;
            _this.showCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      asyncOK: function () {
        var _this = this;
        _this.showCurrentTableData = false;
      },
    }
  };
</script>
